Data Structure
Q101.
The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudocode below is invoked as height(root) to compute the height of a binary tree rooted at the tree pointer root. int height (treeptr n) { if (n == NULL) return -1; if (n \rightarrow left == NULL) if (n \rightarrow right == NULL) return 0; else return B1; else { h1 = height (n \rightarrow left); if (n \rightarrow right == NULL) return (1+h1); else { h2 = height (n \rightarrow right); return B2; } } } The appropriate expressions for the two boxes B1 and B2 areQ104.
A binary tree with n>1 nodes has n_{1}, n_{2} and n_{3} nodes of degree one, two and three respectively. The degree of a node is defined as the number of its neighbors. n_{3} can be expressed asQ105.
A binary tree with n>1 nodes has n_{1}, n_{2} and n_{3} nodes of degree one, two and three respectively. The degree of a node is defined as the number of its neighbors. Starting with the above tree, while there remains a node v of degree two in the tree, add an edge between the two neighbors of v and then remove v from the tree. How many edges will remain at the end of the process?Q106.
The following three are known to be the preorder, inorder and postorder sequences of a binary tree. But it is not known which is which. I.MBCAFHPYK II.KAMCBYPFH III.MABCKYFPH Pick the true statement from the following.Q107.
The in-order traversal of a tree resulted in FBGADCE. Then the pre-order traversal of that tree would result inQ108.
Consider the following C program segment where CellNode represents a node in a binary tree: struct CellNode { struct CellNOde *leftChild; int element; struct CellNode *rightChild; }; int GetValue(struct CellNode *ptr) { int value = 0; if (ptr != NULL) { if ((ptr->leftChild == NULL) && (ptr->rightChild == NULL)) value = 1; else value = value + GetValue(ptr->leftChild) + GetValue(ptr->rightChild); } return(value); } The value returned by GetValue when a pointer to the root of a binary tree is passed as its argument is:Q110.
The inorder and preorder traversal of a binary tree are d b e a f c g and a b d e c f g, respectively The postorder traversal of the binary tree is: